const path = require('path');
const express = require('express');
const logger = require('morgan');

const port = 3000 ;
const app = express();

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));

app.get( '/' , (req,resp)=>{
  resp.redirect( '/index.html' );
});

app.post( '/hello' , (req,resp) => {

  let { username  , password } = req.body ;
  console.log( username , password );

  resp.json( { username , password } );

});

app.get( '/parse' , (req,resp) => {
  // console.log( req.rawHeaders );
  // console.log( req.headers );
  console.log( 'if-none-match: ' , req.headers[ 'if-none-match' ] );
  // resp.json( { id: 1001 , username: '朱亚红' } );
  resp.json( {id: Math.floor( Math.random() * 1000 ) , username: '朱某' } );
});

app.listen( port );